<?php

class Administration_Model_Mapper_Users extends Jnd_Model_Mapper_Abstract
{
    protected $_dict = array(
        'id' => 'idusers', 
        'lastname' => 'lastname', 
        'firstname' => 'firstname', 
        'username' => 'username', 
        'admin' => 'admin', 
        'password' => 'password', 
        'email' => 'email', 
        'avatar' => 'avatar', 
    	'activationKey' => 'activationkey',
        'creationUser' => 'creationuser', 
        'creationDate' => 'creationdate'
    );
    
    protected $_dictDate = array(
        'creationDate' => 'creationdate'
    );

    /**
     * Methode permettant de générer le Table_Select pour le datagrid
     * @see Jnd_Model_Mapper_Abstract::getListSelect()
     */
    public function getListSelect( $values, $environnement, $identite, $options = null )
    {
        $table = $this->_getTable();
        $tableName = $table->info(Zend_Db_Table_Abstract::NAME);
        $dba = $table->getAdapter();
        $select = $dba->select()->from($tableName, $this->_dict, $table->info(Zend_Db_Table_Abstract::SCHEMA));
        
        $champ = 'name';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($tableName . '.' . $this->_dict[$champ]) . ' LIKE ?', '%' . $values[$champ] . '%');
        }
        $champ = 'creationUser';
        if (isset($values[$champ]) && $values[$champ]) {
            $select->where($dba->quoteIdentifier($tableName . '.' . $this->_dict[$champ]) . ' LIKE ?', $values[$champ] . '%');
        }
        $champ = 'creationDate';
        if (isset($values[$champ]) && $values[$champ]) {
            $dt = new Jnd_Date($values[$champ], null, 'fr_FR');
            $select->where('DATE(' . $dba->quoteIdentifier($tableName . '.' . $this->_dict[$champ]) . ') = ?', $dt->getDbDate());
        }
        //      echo $select;
        //        die("Select : $select");
        return $select;
    }
    
	/**
     * @see Jnd_Model_Mapper_Abstract::recuperationDonneesDepuisModel()
     */
    protected function recuperationDonneesDepuisModel( Jnd_Model_Abstract $objetModel )
    {
		$donnees = parent::recuperationDonneesDepuisModel($objetModel);
		if ( $donnees['password'] == "" ) {
			unset($donnees['password']);
		}
		return $donnees;        
    }

    
    
}
